<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编写一个四则运算函数</title>

    <script>
        var a=window.prompt("请输入第1个数：","请输入第1个数");
        var b=window.prompt("请输入第2个数：","请输入第2个数");
        var c=window.prompt("请输运算符号：","请输运算符号");


        function add(a=parseInt(a),b=parseInt (b)) {
            return a+b;
        }
        function jian(a=parseInt(a),b=parseInt (b)) {
            return a-b;
        }
        function cheng(a=parseInt(a),b=parseInt (b)) {
            return a*b;
        }
        function chu(a=parseInt(a),b=parseInt (b)) {
            return a/b;
        }
        if(c=="+"){
            alert(a+"+"+b+"="+add(a,b));
        }else if (c=="-"){
            alert(a+"-"+b+"="+jian(a,b));
        }else if (c=="*"){
            alert(a+"*"+b+"="+cheng(a,b));
        }else if (c=="/"){
            alert(chu(a+"/"+b+"="+a,b));
        }else{
            alert("运算符错误！");
        }

    </script>
</head>
<body >
<!--<input type="button" value="四则运算" onclick="add(a,b)">-->


</body>
</html>